package com.fjw.mapper;

import com.fjw.pojo.Tea;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface TeaMapper {
    // 原有 SQL 操作
    @Insert("INSERT INTO tea (name, rmb, beizhu, type, status) VALUES (#{name}, #{rmb}, #{beizhu}, #{type}, #{status})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void add(Tea tea);

    @Select("SELECT * FROM tea WHERE id = #{id}")
    Tea findById(Integer id);

    @Select("SELECT * FROM tea")
    List<Tea> getAll();

    @Delete("DELETE FROM tea WHERE id = #{id}")
    void deleteById(Integer id);

    @Update("UPDATE tea SET name = #{name}, rmb = #{rmb}, beizhu = #{beizhu}, type = #{type}, status = #{status} WHERE id = #{id}")
    void updateById(Tea tea);

    // 新增根据 name 模糊查询的 SQL，使用 LIKE 拼接关键词
    @Select("SELECT * FROM tea WHERE name LIKE CONCAT('%', #{name}, '%')")
    List<Tea> findByName(String name);

    // 新增SQL
    @Select("SELECT * FROM tea WHERE status = #{status}")
    List<Tea> findByStatus(Integer status);

    // 修改为字符串匹配
    @Select("SELECT * FROM tea WHERE type = #{type}")
    List<Tea> findByType(String type);

    List<Tea> findByIds(List<Integer> teaIdList);
}